import 'package:flutter/material.dart';

/// UI组件库边框令牌
/// 统一管理边框样式和圆角
class UIBorders {
  // 圆角半径
  static const double radiusNone = 0.0;
  static const double radiusXS = 2.0;
  static const double radiusSM = 4.0;
  static const double radiusMD = 8.0;
  static const double radiusLG = 12.0;
  static const double radiusXL = 16.0;
  static const double radiusXXL = 24.0;
  static const double radiusRound = 50.0; // 圆形/胶囊形

  // 边框宽度
  static const double widthNone = 0.0;
  static const double widthThin = 0.5;
  static const double widthMedium = 1.0;
  static const double widthThick = 2.0;
  static const double widthFocus = 2.5;

  // 标准圆角
  static BorderRadius get none => BorderRadius.zero;
  static BorderRadius get xs => BorderRadius.circular(radiusXS);
  static BorderRadius get sm => BorderRadius.circular(radiusSM);
  static BorderRadius get md => BorderRadius.circular(radiusMD);
  static BorderRadius get lg => BorderRadius.circular(radiusLG);
  static BorderRadius get xl => BorderRadius.circular(radiusXL);
  static BorderRadius get xxl => BorderRadius.circular(radiusXXL);
  static BorderRadius get round => BorderRadius.circular(radiusRound);

  // 组件特定圆角
  static BorderRadius get button => md;
  static BorderRadius get buttonSmall => sm;
  static BorderRadius get buttonLarge => lg;

  static BorderRadius get card => lg;
  static BorderRadius get cardSmall => md;
  static BorderRadius get cardLarge => xl;

  static BorderRadius get dialog => xl;
  static BorderRadius get bottomSheet => BorderRadius.vertical(top: Radius.circular(radiusXL));

  static BorderRadius get textField => md;
  static BorderRadius get textFieldSmall => sm;

  static BorderRadius get chip => round;
  static BorderRadius get avatar => round;

  static BorderRadius get image => md;
  static BorderRadius get imageSmall => sm;
  static BorderRadius get imageLarge => lg;

  // 单侧圆角
  static BorderRadius topOnly(double radius) => BorderRadius.vertical(top: Radius.circular(radius));
  static BorderRadius bottomOnly(double radius) => BorderRadius.vertical(bottom: Radius.circular(radius));
  static BorderRadius leftOnly(double radius) => BorderRadius.horizontal(left: Radius.circular(radius));
  static BorderRadius rightOnly(double radius) => BorderRadius.horizontal(right: Radius.circular(radius));

  // 标准边框
  static Border get thin => Border.all(width: widthThin, color: const Color(0xFFE0E0E0));
  static Border get medium => Border.all(width: widthMedium, color: const Color(0xFFE0E0E0));
  static Border get thick => Border.all(width: widthThick, color: const Color(0xFFE0E0E0));

  // 状态边框
  static Border get focus => Border.all(width: widthFocus, color: const Color(0xFF6750A4));
  static Border get error => Border.all(width: widthMedium, color: const Color(0xFFEF4444));
  static Border get success => Border.all(width: widthMedium, color: const Color(0xFF4CAF50));
  static Border get warning => Border.all(width: widthMedium, color: const Color(0xFFFF9800));

  // 自定义边框
  static Border custom({
    double width = widthMedium,
    Color color = const Color(0xFFE0E0E0),
    BorderStyle style = BorderStyle.solid,
  }) {
    return Border.all(width: width, color: color, style: style);
  }

  // 单侧边框
  static Border topBorder({
    double width = widthMedium,
    Color color = const Color(0xFFE0E0E0),
  }) {
    return Border(top: BorderSide(width: width, color: color));
  }

  static Border bottomBorder({
    double width = widthMedium,
    Color color = const Color(0xFFE0E0E0),
  }) {
    return Border(bottom: BorderSide(width: width, color: color));
  }

  static Border leftBorder({
    double width = widthMedium,
    Color color = const Color(0xFFE0E0E0),
  }) {
    return Border(left: BorderSide(width: width, color: color));
  }

  static Border rightBorder({
    double width = widthMedium,
    Color color = const Color(0xFFE0E0E0),
  }) {
    return Border(right: BorderSide(width: width, color: color));
  }

  // 虚线边框
  static BoxDecoration dashedBorder({
    double width = widthMedium,
    Color color = const Color(0xFFE0E0E0),
    double dashWidth = 4.0,
    double dashSpace = 4.0,
  }) {
    return BoxDecoration(
      border: Border.all(color: Colors.transparent),
    );
    // 注：Flutter 原生不支持虚线边框，需要使用第三方包或自定义绘制
  }

  // 渐变边框
  static BoxDecoration gradientBorder({
    required Gradient gradient,
    double width = widthMedium,
    BorderRadius? borderRadius,
  }) {
    return BoxDecoration(
      gradient: gradient,
      borderRadius: borderRadius,
    );
  }

  // 暗色主题边框
  static Border get thinDark => Border.all(width: widthThin, color: const Color(0xFF404040));
  static Border get mediumDark => Border.all(width: widthMedium, color: const Color(0xFF404040));
  static Border get thickDark => Border.all(width: widthThick, color: const Color(0xFF404040));

  // 根据主题获取边框
  static Border getBorder(Brightness brightness, {double width = widthMedium}) {
    return brightness == Brightness.light 
        ? Border.all(width: width, color: const Color(0xFFE0E0E0))
        : Border.all(width: width, color: const Color(0xFF404040));
  }

  // 组合边框样式
  static BoxDecoration getBoxDecoration({
    BorderRadius? borderRadius,
    Border? border,
    List<BoxShadow>? boxShadow,
    Color? color,
    Gradient? gradient,
  }) {
    return BoxDecoration(
      borderRadius: borderRadius,
      border: border,
      boxShadow: boxShadow,
      color: color,
      gradient: gradient,
    );
  }
}